refactor: reuse P2P client across node modes#3065
Conversation
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
|
Claude finished @alpe's task in 2m 3s —— View job Code Review CompleteI've performed a comprehensive code review of this P2P client reuse and pending block storage refactoring PR. Below are my findings organized by category. 1. Architecture & Design Quality
|
Summary of ChangesHello @alpe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the P2P client's lifecycle management within the node architecture. By centralizing the P2P client's creation and making it persistent across node mode switches, it aims to improve startup efficiency and reduce resource overhead. Additionally, it introduces concurrent initialization for synchronization services and strengthens data consistency checks in the store getters, ensuring that only fully committed data is exposed via the P2P layer. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3065 +/- ##
==========================================
- Coverage 61.07% 61.03% -0.05%
==========================================
Files 113 113
Lines 11431 11440 +9
==========================================
Hits 6982 6982
- Misses 3669 3676 +7
- Partials 780 782 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request refactors the P2P client lifecycle and integration within the node architecture. The primary change involves centralizing the creation and management of the P2P client in the FullNode and LightNode constructors, passing an already initialized p2p.Client instance rather than a nodeKey for internal P2P client creation. This ensures the P2P client is long-lived and persists across mode switches (e.g., between aggregator and sync modes), avoiding costly re-initialization of the libp2p stack. Consequently, imports related to p2p/key and ipfs/go-datastore were removed from several files, and failover.go now runs header and data sync services concurrently to improve startup performance. Test helper functions were updated to reflect these changes, now returning crypto.PrivKey and creating p2p.Client instances. Additionally, pkg/store/store_adapter.go was updated to include a height guard in HeaderStoreGetter and DataStoreGetter to prevent serving uncommitted or future block data, and a new test TestHeaderStoreGetter_HeightGuard was added to verify this behavior. A review comment highlighted an inaccuracy in node/failover.go regarding the Reconfigure() call, which should be addressed for clarity.
node/failover.go
Outdated
| } | ||
| defer f.p2pClient.Close() // nolint: errcheck | ||
| // P2P client persists across mode switches (started/closed by FullNode.Run). | ||
| // Reconfigure() was already called in setupFailoverState to re-bootstrap DHT. |
There was a problem hiding this comment.
This comment states that Reconfigure() is called in setupFailoverState, but this call does not appear to be present in the setupFailoverState function. This is misleading and could cause confusion about how the P2P client is reconfigured during mode switches. Please remove or update this comment to accurately reflect the code's behavior.
09f4a76 to
24c7d76
Compare
24c7d76 to
f854686
Compare
|
@claude review again |
|
Claude finished @alpe's task in 2m 21s —— View job Code Review CompleteI've performed a comprehensive code review of this P2P client refactoring PR. Here are my findings: OverviewThis PR successfully refactors the P2P client lifecycle to be centralized and reused across node mode switches (aggregator ↔ sync). The core architectural improvement is solid, moving P2P client creation from individual mode constructors to the top-level node initialization. However, there are several important issues that should be addressed. Critical Issues1. Thread-Safety Race Condition in
|
| File | Coverage | Missing Lines |
|---|---|---|
node/failover.go |
60.00% | 3 missing, 3 partial |
node/full.go |
50.00% | 2 missing, 2 partial |
pkg/cmd/run_node.go |
0.00% | 4 missing |
node/light.go |
0.00% | 1 missing, 1 partial |
pkg/p2p/client.go |
75.00% | 1 missing, 1 partial |
node/node.go |
50.00% | 1 missing |
Recommendations Summary
Must Fix (Before Merge):
- ⛔ Fix thread-safety race in
startedflag - Useatomic.Bool ⚠️ Add explicit cleanup for partial sync service startup failures⚠️ Clarify P2P reconfiguration strategy - Document or implement
Should Fix:
- 📊 Improve test coverage - Add integration tests for P2P client reuse and mode switches
- 🔍 Add compile-time interface check for
P2PClient - 📝 Document idempotent
Start()behavior
Nice to Have:
- Consider propagating P2P close errors in shutdown
- Improve error messages with more context
- Verify
rktStoreusage is correct for both sync services
Overall Assessment
This is a solid architectural refactoring that addresses real performance and resource management issues. The core design is sound, but there are critical thread-safety and error handling gaps that must be addressed before merging.
Recommendation: Request changes to address the thread-safety issue (#1), partial failure cleanup (#4), and P2P reconfiguration clarity (#3). Test coverage improvements (#4) are also highly recommended.
The concurrent sync service startup optimization is excellent, but needs better error handling. Once the critical issues are addressed, this will be a valuable improvement to the codebase.
julienrbrt
left a comment
There was a problem hiding this comment.
utACK! I saw CI green on ev-abci too, nice!
Refactor P2P client reuse and pending block storage
This PR introduces improvements to the P2P client lifecycle management and pending block storage:
Key Changes: